package com.ly.web.controller.erp;

import java.util.List;

import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.core.page.TableDataInfo;
import com.ly.common.enums.BusinessType;
import com.ly.common.utils.poi.ExcelUtil;
import com.ly.heart.domain.KingAllocateInfoEntity;
import com.ly.heart.domain.KingApplyAllocateEntity;
import com.ly.heart.service.IKingAllocateInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * new调拨单Controller
 *
 * @author wutao
 * @date 2024-08-07
 */
@RestController
@RequestMapping("/heart/allocateInfo")
public class KingAllocateInfoController extends BaseController {
    @Autowired
    private IKingAllocateInfoService erpKingAllocateInfoService;

    /**
     * 查询new调拨单列表
     */
    @PreAuthorize("@ss.hasPermi('heart:allocateInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(KingAllocateInfoEntity erpKingAllocateInfo) {
        startPage();
        List<KingAllocateInfoEntity> list = erpKingAllocateInfoService.selectErpKingAllocateInfoList(erpKingAllocateInfo);
        return getDataTable(list);
    }

    /**
     * 导出new调拨单列表
     */
    @PreAuthorize("@ss.hasPermi('heart:allocateInfo:export')")
    @Log(title = "new调拨单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(KingAllocateInfoEntity erpKingAllocateInfo) {
        List<KingAllocateInfoEntity> list = erpKingAllocateInfoService.selectErpKingAllocateInfoList(erpKingAllocateInfo);
        ExcelUtil<KingAllocateInfoEntity> util = new ExcelUtil<KingAllocateInfoEntity>(KingAllocateInfoEntity.class);
        return util.exportExcel(list, "allocateInfo");
    }

    /**
     * 获取new调拨单详细信息
     */
    @PreAuthorize("@ss.hasPermi('heart:allocateInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(erpKingAllocateInfoService.selectErpKingAllocateInfoById(id));
    }

    /**
     * 暂存金蝶-调拨单
     *
     * @param kingAllocateInfo
     * @return
     */
    @ApiOperation("暂存金蝶-调拨单")
    @PreAuthorize("@ss.hasPermi('heart:applyAllocate:draft')")
    @Log(title = "暂存金蝶-调拨单", businessType = BusinessType.INSERT)
    @PostMapping("/draft")
    public AjaxResult draft(@RequestBody KingAllocateInfoEntity kingAllocateInfo) {
        return erpKingAllocateInfoService.draft(kingAllocateInfo);
    }

    /**
     * 保存金蝶-调拨申请单
     *
     * @param kingAllocateInfo
     * @return
     */
    @ApiOperation("保存金蝶-调拨申请单")
    @PreAuthorize("@ss.hasPermi('heart:applyAllocate:submit')")
    @Log(title = "保存金蝶-调拨申请单", businessType = BusinessType.INSERT)
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody KingAllocateInfoEntity kingAllocateInfo) {
        return erpKingAllocateInfoService.submit(kingAllocateInfo);
    }

    /**
     * 修改new调拨单
     */
    @PreAuthorize("@ss.hasPermi('heart:allocateInfo:edit')")
    @Log(title = "new调拨单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KingAllocateInfoEntity erpKingAllocateInfo) {
        return toAjax(erpKingAllocateInfoService.updateErpKingAllocateInfo(erpKingAllocateInfo));
    }

    /**
     * 删除new调拨单
     */
    @PreAuthorize("@ss.hasPermi('heart:allocateInfo:remove')")
    @Log(title = "new调拨单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(erpKingAllocateInfoService.deleteErpKingAllocateInfoByIds(ids));
    }
}
